import { _decorator, Component, Node, UITransform, v2, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Camera')
export class Camera extends Component {
    @property(Node)
    player: Node = null;
    start() {

    }

    update(deltaTime: number) {

        if (!this.player) return;

        let w_pos = this.player.getComponent(UITransform).convertToWorldSpaceAR(new Vec3(0, 0, 0));
        let m_pos = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(w_pos);

        this.node.position = m_pos;

    }
}


